package conf

var ConfTpl = `
package conf

import (
    "fmt"
    "github.com/spf13/viper"
)

type ConfigViper struct {
    Mysql  Mysql
    Redis  Redis
    Consul Consul
    Chain  Chain
    Ali    AliYunPay
    Nacos  struct {
        Host        string
        Port        int
        NamespaceId string
        DataId      string
        Group       string
    }
}

var Cfg ConfigViper

func Init() {
    viper.SetConfigName("config")
    viper.SetConfigType("yaml")
    viper.AddConfigPath("./cmd/apps")

    err := viper.ReadInConfig()
    if err != nil {
        fmt.Println("配置读取失败")
        panic(err)
    }
    err = viper.Unmarshal(&Cfg)
    if err != nil {
        fmt.Println("数据解析失败")
        panic(err)
    }
    NaCosInit()
}

type Mysql struct {
    User      string
    Pwd       string
    Host      string
    Port      int
    Databases string
}

type Redis struct {
    Addr     string
    Password string
    Db       int
}

type Consul struct {
    Host     string
    Port     int
    Services []Services
}

type Services struct {
    Name string
    Host string
    Port int
}

type Chain struct {
    Enable bool
    Host   string
    Port   int
    Name   string
}

type AliYunPay struct {
    AppId string
    AliPublicKey string
    PrivateKey string
    NotifyUrl string
    ReturnUrl string
}`
